package net.kem.android.positioner.custom;

import net.kem.android.positioner.MessageObject;
import net.kem.android.positioner.PositionerService;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ServerMessageElement extends LinearLayout {
	protected MessageObject messageObject;
	protected PositionerService.LocalBinder binder;
	protected ImageView image;
	protected TextView text;

	public ServerMessageElement(PositionerService.LocalBinder binder, Context context, MessageObject messageObject) {
		this(binder, context, (AttributeSet)null, messageObject);
	}
	public ServerMessageElement(PositionerService.LocalBinder binder, Context context, AttributeSet attrs, MessageObject messageObject) {
		super(context, attrs);
		this.binder = binder;
		this.messageObject = messageObject;
		text = new TextView(context);
		text.setMinWidth(200);
		text.setMaxWidth(200);
		text.setLines(1);
		text.setEllipsize(TextUtils.TruncateAt.END);
		text.setPadding(5, 0, 0, 5);
		String label = messageObject.getName();
		if(label == null) {
			label = "";
		}
//		if(label.length() > 12) {
//			label = label.substring(0, 12);
//		} else {
//			int ws = 12 - label.length();
//			for(int i=0; i<ws; i++) {
//				label = label + ' ';
//			}
//		}
		text.setText(label);
		addView(text);
	}

	public TextView getText() {
		return text;
	}
	public void setText(TextView text) {
		this.text = text;
	}

	public ImageView getImage() {
		return image;
	}

	public void setImage(ImageView image) {
		if(this.image != null) {
			removeView(this.image);
		}
		this.image = image;
		addView(image, 0);
	}

	public void setActive(boolean isActive) {
		if(isActive) {
			//image.setAlpha(2);
		} else {
			//image.setAlpha(1);
		}
	}


	/*@Override
	protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
		image.layout(left, top, right, bottom);
		view.layout(left, top, right, bottom);
	}*/

}
